<template>
  <el-tabs
    class="work"
    v-model="activeName"
    type="border-card"
    @tab-click="handleClick"
  >
    <el-tab-pane label="身份验证" name="first">
      <div class="check">
        <div class="user">
          <img
            src="../assets/forgetpassword/user.png"
            alt=""
            :class="uemail1"
          />
          <input
            placeholder="输入注册邮箱"
            type="email"
            v-model="email"
            :class="uemail2"
          />
          <button class="getemail" @click="getAuthCode()">{{ content }}</button>
        </div>
        <div class="email">
          <img src="../assets/forgetpassword/email.png" alt="" />
          <input
            type="text"
            placeholder="输入邮箱验证码"
            v-model="emailVerificationCode"
          />
        </div>
        <div class="buttom">
          <button class="next" @click="toSecond">下一步</button>
          <button class="next">重置</button>
        </div>
        <div class="online"></div>
      </div>
    </el-tab-pane>
    <el-tab-pane label="密码重置" name="second">
      <div class="check">
        <div class="user">
          <img src="../assets/forgetpassword/pwd.png" alt="" />
          <input name="pwd1" type="password" placeholder="输入新密码" />
        </div>
        <div class="email">
          <img src="../assets/forgetpassword/pwd.png" alt="" />
          <input name="pwd1" type="password" placeholder="确认密码" />
        </div>
        <div class="buttom">
          <button class="next" @click="toThird">下一步</button>
          <button class="next">重置</button>
        </div>
        <div class="online"></div>
      </div>
    </el-tab-pane>
    <el-tab-pane label="重置完成" name="third">
      <div class="check">
        <div class="succe">
          <img src="../assets/forgetpassword/suse.png" alt="" />
        </div>
        <div class="text">重置成功</div>
        <div class="buttom">
          <button class="next">
            <router-link to="/login">去登陆</router-link>
          </button>
        </div>
      </div>
    </el-tab-pane>
  </el-tabs>
</template>
<style>
* {
  margin: 0;
  padding: 0;
}
.work {
  background: white;
  width: 600px;
  border: 1px solid #e5e5e5;
  margin: 0 auto;
  text-align: center;
  margin-top: 3%;
  border-radius: 3px;
}

/* 输入框样式 */

.work .check {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 30px;
}
.work .user,
.work .email {
  width: 400px;
  height: 60px;
  background-color: #e5e5e5;
  margin-top: 30px;
  display: flex;
  justify-content: left;
  border-radius: 3px;
}
.work input {
  background-color: #e5e5e5;
  border: 0;
}
.work input:focus {
  outline: none;
}
.work img {
  width: 24px;
  height: 24px;
  margin-top: 18px;
  margin-right: 12px;
  margin-left: 12px;
}
.work button {
  border: 0;
  width: 150px;
  height: 40px;
  background-color: white;
  margin-top: 9px;
  margin-left: 12px;
  border-radius: 3px;
  color: #707070;
}
.work .disabled {
  background-color: #ddd;
  border-color: #ddd;
  color: #57a3f3;
  cursor: not-allowed;
}

/* 底部按钮 */
.work .succe img {
  width: 93px;
  height: 90px;
}
.work .text {
  color: #1296db;
  font-size: 48px;
}
.work .buttom {
  display: flex;
}
.work .next {
  width: 70px;
  height: 40px;
  border: 0;
  background-color: #1296db;
  border-radius: 3px;
  color: white;
  margin: 30px;
}
.work a {
  color: #fff;
}
.work a:hover {
  color: #fff;
  text-decoration: none;
}
</style>
<script>
export default {
  data() {
    return {
      email: "",
      emailVerificationCode: "",
      uemail1: "uemail",
      uemail2: "",
      activeName: "first",
      content: "发送验证码", // 按钮里显示的内容
      totalTime: 60, //记录具体倒计时时间
      canClick: true, //添加canClick
    };
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
      tab.index + 1;
    },
    getAuthCode() {
      if (!this.canClick) {
        this.canClick = false;
      } else {
        this.axios.get("/send?uemail=" + this.email);
        window.alert("邮件已发送到您的邮箱，请前去激活。");
      }
      this.content = this.totalTime + "s后重新发送"; //解决60秒不见了的问题
      let clock = window.setInterval(() => {
        this.totalTime--;
        this.content = this.totalTime + "s后重新发送";
        if (this.totalTime < 0) {
          //当倒计时小于0时清除定时器
          window.clearInterval(clock);
          this.content = "重新发送验证码";
          this.totalTime = 60;
          this.canClick = true; //这里重新开启
        }
      }, 1000);
    },
    regEmail() {
      //邮箱验证
      let emailReg = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
      if (emailReg.test(this.email)) {
        this.uemail1 = "uemail";
        this.uemail2 = "";
        return true;
      } else {
        this.uemail1 = "uemail noemail";
        this.uemail2 = "noemail";
        return false;
      }
    },
    toSecond() {
      this.activeName = "second";
    },
    toThird() {
      this.activeName = "third";
    },
  },
};
</script>